﻿///////////////////////////////////////////////////////////////
// This is generated code. 
//////////////////////////////////////////////////////////////
// Code is generated using LLBLGen Pro version: 4.2
// Code is generated on: 
// Code is generated using templates: SD.TemplateBindings.SharedTemplates
// Templates vendor: Solutions Design.
////////////////////////////////////////////////////////////// 
using System;
using System.Linq;
using VNet.VisiSuite.VisiBoard.Dal.EntityClasses;
using VNet.VisiSuite.VisiBoard.Dal.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using SD.LLBLGen.Pro.QuerySpec;

namespace VNet.VisiSuite.VisiBoard.Dal.FactoryClasses
{
	/// <summary>Factory class to produce DynamicQuery instances and EntityQuery instances</summary>
	public partial class QueryFactory
	{
		private int _aliasCounter = 0;

		/// <summary>Creates a new DynamicQuery instance with no alias set.</summary>
		/// <returns>Ready to use DynamicQuery instance</returns>
		public DynamicQuery Create()
		{
			return Create(string.Empty);
		}

		/// <summary>Creates a new DynamicQuery instance with the alias specified as the alias set.</summary>
		/// <param name="alias">The alias.</param>
		/// <returns>Ready to use DynamicQuery instance</returns>
		public DynamicQuery Create(string alias)
		{
			return new DynamicQuery(new ElementCreator(), alias, this.GetNextAliasCounterValue());
		}

		/// <summary>Creates a new DynamicQuery which wraps the specified TableValuedFunction call</summary>
		/// <param name="toWrap">The table valued function call to wrap.</param>
		/// <returns>toWrap wrapped in a DynamicQuery.</returns>
		public DynamicQuery Create(TableValuedFunctionCall toWrap)
		{
			return this.Create().From(new TvfCallWrapper(toWrap)).Select(toWrap.GetFieldsAsArray().Select(f => this.Field(toWrap.Alias, f.Alias)).ToArray());
		}

		/// <summary>Creates a new EntityQuery for the entity of the type specified with no alias set.</summary>
		/// <typeparam name="TEntity">The type of the entity to produce the query for.</typeparam>
		/// <returns>ready to use EntityQuery instance</returns>
		public EntityQuery<TEntity> Create<TEntity>()
			where TEntity : IEntityCore
		{
			return Create<TEntity>(string.Empty);
		}

		/// <summary>Creates a new EntityQuery for the entity of the type specified with the alias specified as the alias set.</summary>
		/// <typeparam name="TEntity">The type of the entity to produce the query for.</typeparam>
		/// <param name="alias">The alias.</param>
		/// <returns>ready to use EntityQuery instance</returns>
		public EntityQuery<TEntity> Create<TEntity>(string alias)
			where TEntity : IEntityCore
		{
			return new EntityQuery<TEntity>(new ElementCreator(), alias, this.GetNextAliasCounterValue());
		}
				
		/// <summary>Creates a new field object with the name specified and of resulttype 'object'. Used for referring to aliased fields in another projection.</summary>
		/// <param name="fieldName">Name of the field.</param>
		/// <returns>Ready to use field object</returns>
		public EntityField2 Field(string fieldName)
		{
			return Field<object>(string.Empty, fieldName);
		}

		/// <summary>Creates a new field object with the name specified and of resulttype 'object'. Used for referring to aliased fields in another projection.</summary>
		/// <param name="targetAlias">The alias of the table/query to target.</param>
		/// <param name="fieldName">Name of the field.</param>
		/// <returns>Ready to use field object</returns>
		public EntityField2 Field(string targetAlias, string fieldName)
		{
			return Field<object>(targetAlias, fieldName);
		}

		/// <summary>Creates a new field object with the name specified and of resulttype 'TValue'. Used for referring to aliased fields in another projection.</summary>
		/// <typeparam name="TValue">The type of the value represented by the field.</typeparam>
		/// <param name="fieldName">Name of the field.</param>
		/// <returns>Ready to use field object</returns>
		public EntityField2 Field<TValue>(string fieldName)
		{
			return Field<TValue>(string.Empty, fieldName);
		}

		/// <summary>Creates a new field object with the name specified and of resulttype 'TValue'. Used for referring to aliased fields in another projection.</summary>
		/// <typeparam name="TValue">The type of the value.</typeparam>
		/// <param name="targetAlias">The alias of the table/query to target.</param>
		/// <param name="fieldName">Name of the field.</param>
		/// <returns>Ready to use field object</returns>
		public EntityField2 Field<TValue>(string targetAlias, string fieldName)
		{
			return new EntityField2(fieldName, targetAlias, typeof(TValue));
		}
		
		/// <summary>Gets the next alias counter value to produce artifical aliases with</summary>
		private int GetNextAliasCounterValue()
		{
			_aliasCounter++;
			return _aliasCounter;
		}
		

		/// <summary>Creates and returns a new EntityQuery for the AlarmSetting entity</summary>
		public EntityQuery<AlarmSettingEntity> AlarmSetting
		{
			get { return Create<AlarmSettingEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the Area entity</summary>
		public EntityQuery<AreaEntity> Area
		{
			get { return Create<AreaEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the AreaShift entity</summary>
		public EntityQuery<AreaShiftEntity> AreaShift
		{
			get { return Create<AreaShiftEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the BraiderProduct entity</summary>
		public EntityQuery<BraiderProductEntity> BraiderProduct
		{
			get { return Create<BraiderProductEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the Cell entity</summary>
		public EntityQuery<CellEntity> Cell
		{
			get { return Create<CellEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the CellAlarmSetting entity</summary>
		public EntityQuery<CellAlarmSettingEntity> CellAlarmSetting
		{
			get { return Create<CellAlarmSettingEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the CellShift entity</summary>
		public EntityQuery<CellShiftEntity> CellShift
		{
			get { return Create<CellShiftEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the CellStatus entity</summary>
		public EntityQuery<CellStatusEntity> CellStatus
		{
			get { return Create<CellStatusEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the DatabaseVersion entity</summary>
		public EntityQuery<DatabaseVersionEntity> DatabaseVersion
		{
			get { return Create<DatabaseVersionEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the FractionalInch entity</summary>
		public EntityQuery<FractionalInchEntity> FractionalInch
		{
			get { return Create<FractionalInchEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the HoseSpec entity</summary>
		public EntityQuery<HoseSpecEntity> HoseSpec
		{
			get { return Create<HoseSpecEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the LaunchApplication entity</summary>
		public EntityQuery<LaunchApplicationEntity> LaunchApplication
		{
			get { return Create<LaunchApplicationEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the Operation entity</summary>
		public EntityQuery<OperationEntity> Operation
		{
			get { return Create<OperationEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the Operator entity</summary>
		public EntityQuery<OperatorEntity> Operator
		{
			get { return Create<OperatorEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the OperatorAuth entity</summary>
		public EntityQuery<OperatorAuthEntity> OperatorAuth
		{
			get { return Create<OperatorAuthEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the Plant entity</summary>
		public EntityQuery<PlantEntity> Plant
		{
			get { return Create<PlantEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the Product entity</summary>
		public EntityQuery<ProductEntity> Product
		{
			get { return Create<ProductEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the ProductionHistory entity</summary>
		public EntityQuery<ProductionHistoryEntity> ProductionHistory
		{
			get { return Create<ProductionHistoryEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the ProductionHistoryDowntimeEvent entity</summary>
		public EntityQuery<ProductionHistoryDowntimeEventEntity> ProductionHistoryDowntimeEvent
		{
			get { return Create<ProductionHistoryDowntimeEventEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the ProductionHistoryUndoBuffer entity</summary>
		public EntityQuery<ProductionHistoryUndoBufferEntity> ProductionHistoryUndoBuffer
		{
			get { return Create<ProductionHistoryUndoBufferEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the ProductionPlan entity</summary>
		public EntityQuery<ProductionPlanEntity> ProductionPlan
		{
			get { return Create<ProductionPlanEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the ProductOperationTime entity</summary>
		public EntityQuery<ProductOperationTimeEntity> ProductOperationTime
		{
			get { return Create<ProductOperationTimeEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the ReasonCode entity</summary>
		public EntityQuery<ReasonCodeEntity> ReasonCode
		{
			get { return Create<ReasonCodeEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the RollupDefinition entity</summary>
		public EntityQuery<RollupDefinitionEntity> RollupDefinition
		{
			get { return Create<RollupDefinitionEntity>(); }
		}

		/// <summary>Creates and returns a new EntityQuery for the TableDataChange entity</summary>
		public EntityQuery<TableDataChangeEntity> TableDataChange
		{
			get { return Create<TableDataChangeEntity>(); }
		}

 

	}
}